package coc.core;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 爬虫采集结果。
 */
public class CrawlerResult implements Serializable {
	/** 任务ID */
	private String taskId;
	/** 任务名称 */
	private String taskName;
	/** 启动时间 */
	private Date startupDate;
	/** 完成时间 */
	private Date completeDate;
	/** 作业数 */
	private Integer jobCount = 0;
	/** 完成作业数 */
	private Integer completedJobCount = 0;
	/** 异常作业数 */
	private Integer exceptionJobCount = 0;
	/** 采集记录数 */
	private Integer collectRecordCount = 0;
	/** 蜘蛛采集结果集合 */
	private List<SpiderResult> spiderResults = new ArrayList<SpiderResult>();

	/**
	 * 增加完成作业数。
	 */
	public void addCompletedJobCount() {
		completedJobCount++;
	}

	/**
	 * 增加异常作业数。
	 */
	public void addExceptionJobCount() {
		exceptionJobCount++;
	}

	/**
	 * 增加采集记录数。
	 */
	public void addCollectRecordCount() {
		collectRecordCount++;
	}

	/**
	 * 增加蜘蛛采集结果。
	 * 
	 * @param spiderResult
	 *            蜘蛛采集结果
	 */
	public void addSpiderResult(SpiderResult spiderResult) {
		spiderResults.add(spiderResult);
	}

	/**
	 * 增加采集记录数。
	 * 
	 * @param count
	 *            增加量
	 */
	public void addCollectRecordCount(Integer count) {
		collectRecordCount += count;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("[" + taskId + "][" + taskName + "]");
		builder.append("[");
		builder.append(" 分解作业数: " + jobCount);
		builder.append(" 完成作业数: " + completedJobCount);
		builder.append(" 异常作业数: " + exceptionJobCount);
		builder.append(" 采集记录数: " + collectRecordCount);
		builder.append(" 共耗时: "
				+ (completeDate.getTime() - startupDate.getTime()) / 1000
				+ "秒 ");
		builder.append("]");
		return builder.toString();
	}

	public String getTaskId() {
		return taskId;
	}

	public void setTaskId(String taskId) {
		this.taskId = taskId;
	}

	public String getTaskName() {
		return taskName;
	}

	public void setTaskName(String taskName) {
		this.taskName = taskName;
	}

	public Date getStartupDate() {
		return startupDate;
	}

	public void setStartupDate(Date startupDate) {
		this.startupDate = startupDate;
	}

	public Date getCompleteDate() {
		return completeDate;
	}

	public void setCompleteDate(Date completeDate) {
		this.completeDate = completeDate;
	}

	public Integer getJobCount() {
		return jobCount;
	}

	public void setJobCount(Integer jobCount) {
		this.jobCount = jobCount;
	}

	public Integer getCompletedJobCount() {
		return completedJobCount;
	}

	public void setCompletedJobCount(Integer completedJobCount) {
		this.completedJobCount = completedJobCount;
	}

	public Integer getExceptionJobCount() {
		return exceptionJobCount;
	}

	public void setExceptionJobCount(Integer exceptionJobCount) {
		this.exceptionJobCount = exceptionJobCount;
	}

	public Integer getCollectRecordCount() {
		return collectRecordCount;
	}

	public void setCollectRecordCount(Integer collectRecordCount) {
		this.collectRecordCount = collectRecordCount;
	}

	public List<SpiderResult> getSpiderResults() {
		return spiderResults;
	}

	public void setSpiderResults(List<SpiderResult> spiderResults) {
		this.spiderResults = spiderResults;
	}
}
